﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SharpSoft.WPF.Framework
{
    using System.Windows;
    using System.Windows.Controls; 
    using System.Collections.ObjectModel;
    public class DataPage : Page
    {
        public DataPage()
        {
            this.Loaded += DataPage_Loaded;
            this.CustomButtons = new ObservableCollection<ToolbarButton>();
        }

        private void DataPage_Loaded(object sender, RoutedEventArgs e)
        {
            OnLoadBaseData();
            if (this.RefreshOnLoaded)
            {
                this.RefreshData();
            }
        }

        #region Method
        /// <summary>
        /// 加载基础数据
        /// </summary>
        protected virtual void OnLoadBaseData()
        {

        }

        public void RefreshData()
        {
            OnRefreshData();
        }

        protected virtual void OnRefreshData()
        {

        }

        public void InsertData()
        {
            OnInsertData();
        }
        protected virtual void OnInsertData()
        {

        }

        public void DeleteData()
        {
            OnDeleteData();
        }
        protected virtual void OnDeleteData()
        {

        }
        public void EditData()
        {
            OnEditData();
        }
        protected virtual void OnEditData()
        {

        }
        public void SearchData(string keyword)
        {
            OnSearchData(keyword);
        }
        protected virtual void OnSearchData(string keyword)
        {

        }
        public void PostData()
        {
            OnPostData();
        }
        protected virtual void OnPostData()
        {

        }

        public void ImportData()
        {
            this.OnImportData();
        }
        protected virtual void OnImportData()
        {

        }
        public void ExportData()
        {
            this.OnExportData();
        }

        protected virtual void OnExportData()
        {

        }
        #endregion

        #region Properties


        public bool RefreshOnLoaded
        {
            get { return (bool)GetValue(RefreshOnLoadedProperty); }
            set { SetValue(RefreshOnLoadedProperty, value); }
        }

        public static readonly DependencyProperty RefreshOnLoadedProperty =
            DependencyProperty.Register("RefreshOnLoaded", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool CanRefresh
        {
            get { return (bool)GetValue(CanRefreshProperty); }
            set { SetValue(CanRefreshProperty, value); }
        }

        public static readonly DependencyProperty CanRefreshProperty =
            DependencyProperty.Register("CanRefresh", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool NeedRefresh
        {
            get { return (bool)GetValue(NeedRefreshProperty); }
            set { SetValue(NeedRefreshProperty, value); }
        }

        public static readonly DependencyProperty NeedRefreshProperty =
            DependencyProperty.Register("NeedRefresh", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool CanInsert
        {
            get { return (bool)GetValue(CanInsertProperty); }
            set { SetValue(CanInsertProperty, value); }
        }

        public static readonly DependencyProperty CanInsertProperty =
            DependencyProperty.Register("CanInsert", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool NeedInsert
        {
            get { return (bool)GetValue(NeedInsertProperty); }
            set { SetValue(NeedInsertProperty, value); }
        }

        public static readonly DependencyProperty NeedInsertProperty =
            DependencyProperty.Register("NeedInsert", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool CanEdit
        {
            get { return (bool)GetValue(CanEditProperty); }
            set { SetValue(CanEditProperty, value); }
        }

        public static readonly DependencyProperty CanEditProperty =
            DependencyProperty.Register("CanEdit", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool NeedEdit
        {
            get { return (bool)GetValue(NeedEditProperty); }
            set { SetValue(NeedEditProperty, value); }
        }

        public static readonly DependencyProperty NeedEditProperty =
            DependencyProperty.Register("NeedEdit", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool CanDelete
        {
            get { return (bool)GetValue(CanDeleteProperty); }
            set { SetValue(CanDeleteProperty, value); }
        }

        public static readonly DependencyProperty CanDeleteProperty =
            DependencyProperty.Register("CanDelete", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool NeedDelete
        {
            get { return (bool)GetValue(NeedDeleteProperty); }
            set { SetValue(NeedDeleteProperty, value); }
        }

        public static readonly DependencyProperty NeedDeleteProperty =
            DependencyProperty.Register("NeedDelete", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool CanPost
        {
            get { return (bool)GetValue(CanPostProperty); }
            set { SetValue(CanPostProperty, value); }
        }

        public static readonly DependencyProperty CanPostProperty =
            DependencyProperty.Register("CanPost", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool NeedPost
        {
            get { return (bool)GetValue(NeedPostProperty); }
            set { SetValue(NeedPostProperty, value); }
        }

        public static readonly DependencyProperty NeedPostProperty =
            DependencyProperty.Register("NeedPost", typeof(bool), typeof(DataPage), new PropertyMetadata(false));




        public bool CanSearch
        {
            get { return (bool)GetValue(CanSearchProperty); }
            set { SetValue(CanSearchProperty, value); }
        }

        public static readonly DependencyProperty CanSearchProperty =
            DependencyProperty.Register("CanSearch", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool NeedSearch
        {
            get { return (bool)GetValue(NeedSearchProperty); }
            set { SetValue(NeedSearchProperty, value); }
        }

        public static readonly DependencyProperty NeedSearchProperty =
            DependencyProperty.Register("NeedSearch", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool CanImport
        {
            get { return (bool)GetValue(CanImportProperty); }
            set { SetValue(CanImportProperty, value); }
        }

        public static readonly DependencyProperty CanImportProperty =
            DependencyProperty.Register("CanImport", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool NeedImport
        {
            get { return (bool)GetValue(NeedImportProperty); }
            set { SetValue(NeedImportProperty, value); }
        }

        public static readonly DependencyProperty NeedImportProperty =
            DependencyProperty.Register("NeedImport", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool CanExport
        {
            get { return (bool)GetValue(CanExportProperty); }
            set { SetValue(CanExportProperty, value); }
        }

        public static readonly DependencyProperty CanExportProperty =
            DependencyProperty.Register("CanExport", typeof(bool), typeof(DataPage), new PropertyMetadata(false));




        public bool NeedExport
        {
            get { return (bool)GetValue(NeedExportProperty); }
            set { SetValue(NeedExportProperty, value); }
        }

        public static readonly DependencyProperty NeedExportProperty =
            DependencyProperty.Register("NeedExport", typeof(bool), typeof(DataPage), new PropertyMetadata(false));



        public bool NeedToolbar
        {
            get { return (bool)GetValue(NeedToolbarProperty); }
            set { SetValue(NeedToolbarProperty, value); }
        }

        public static readonly DependencyProperty NeedToolbarProperty =
            DependencyProperty.Register("NeedToolbar", typeof(bool), typeof(DataPage), new PropertyMetadata(false));


        #endregion





        public ObservableCollection<ToolbarButton> CustomButtons
        {
            get { return (ObservableCollection<ToolbarButton>)GetValue(CustomButtonsProperty); }
            set { SetValue(CustomButtonsProperty, value); }
        }

        public static readonly DependencyProperty CustomButtonsProperty =
            DependencyProperty.Register("CustomButtons", typeof(ObservableCollection<ToolbarButton>), typeof(DataPage));



    }
}
